-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: AG-UI adapter (toolsets) #2101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: toolsets
Are you sure you want to change the base?
Conversation
PR Change SummaryImplemented the AG-UI adapter for seamless integration with the AG-UI protocol, enhancing user interaction capabilities for PydanticAI agents.
Modified Files
Added Files
How can I customize these reviews?Check out the Hyperlint AI Reviewer docs for more information on how to customize the review. If you just want to ignore it on this PR, you can add the Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add |
caddcc0
to
6671164
Compare
Hey! I know this is still a draft, but have been following the development of ag-ui support since I wish to build my MVP with pydantic-ai & ag-ui. Did a test run today on this branch, dropping my findings in case they are helpful:
|
Great info, keep it coming! |
a391a93
to
2995d59
Compare
There's been some changes on toolset PR, which this depends on and has been updated, can you retest to see if these are fixed now @dorukgezici |
@stevenh concurrent tool calls worked well now! |
2995d59
to
78da22f
Compare
Could you clarify what you mean by wasn't aware of the tool? Do you mean an AG-UI tool wasn't available? |
78da22f
to
1bad3e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stevenh Looking good! Left some questions and suggestions
@@ -204,6 +204,7 @@ jobs: | |||
enable-cache: true | |||
|
|||
- run: uv sync --package pydantic-ai-slim --only-dev | |||
- run: rm coverage/.coverage.*-py3.9-* # Exclude 3.9 coverage as it gets the wrong line numbers, causing invalid failures. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this from this PR and perhaps add it in a separate one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add that to get checks to complete, otherwise they abort early. If you're happy to merge with checks failing, I can extract.
@@ -221,6 +223,15 @@ include = [ | |||
] | |||
omit = ["tests/test_live.py", "tests/example_modules/*.py"] | |||
branch = true | |||
disable_warnings = ["include-ignored"] | |||
|
|||
[tool.coverage.paths] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should remove this before we merge this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prevents tests failing with coverage enabled in VS code, happy to move to a seperate PR?
# specifically, it logs every request and response including binary | ||
# content in Cassette.append, which is causing log downloads from | ||
# GitHub action to fail. | ||
logging.getLogger('vcr.cassette').setLevel(logging.WARNING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give an example of the types of verbose logging we were seeing before, that we're now not anymore? Just to know the tradeoff here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It logs the binary output of requests, including image data. This made logs so large I couldn't even download them from github to investigate a failure, possibly a github bug as no matter what I did the log zip download failed.
I did raise an issue with upstream, as it logs all requests at INFO, but it seems unmaintained.
yield ToolCallArgsEvent( | ||
type=EventType.TOOL_CALL_ARGS, | ||
tool_call_id=agent_event.delta.tool_call_id | ||
or stream_ctx.last_tool_call_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to store this last tool call ID? If there's an ID on the start event, but not on the delta, that'd be a Pydantic AI bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agent_event.delta.tool_call_id
can be None
, if that was a required field, which I suspect it should this wouldn't be needed.
|
||
# Enums. | ||
# TODO(steve): Remove this and all uses once https://github.com/ag-ui-protocol/ag-ui/pull/49 is merged. | ||
class Role(str, Enum): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can drop this and just hard-code string values, they're defined as Literals on the event classes so they're type-checked for validity anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could but that results in repeated values, which is less efficient. I was hoping we could get these eliminated before we merge.
examples/pydantic_ai_ag_ui_examples/api/agentic_generative_ui.py
Outdated
Show resolved
Hide resolved
1db1afb
to
639d60b
Compare
AG-UI adapter enabling integration with the AG-UI protocol via the Agent.to_ag_ui() method. This includes a full example for all features in the AG-UI dojo. Fixes: ag-ui-protocol/ag-ui/issues/5
Move pydantic_ai_ag_ui to pydantic_ai_slim as ag_ui, updating references and documentation accordingly.
Refactor to_ag_ui so it now returns a ASGI compatible server based off starlette. This makes it easier for users setup apps with minimal code. Fix some invalid references missed in the package refactor for cli and examples. Made enums, and exceptions private to the package, so they are not exposed in the public API.
Eliminate the use of match statement and dataclass(kw_only=True) to ensure compatibility with Python 3.9. Remove duplicate import of starlette outside try block, causing tests to fail when it's not installed.
Disable the deprecation warning for model_fields in Mistral.
Remove invalid no cover comment from Mistral model flagged by strict-no-cover check.
Add support for the new tool call returns and thinking parts to the AG UI adapter. This eliminates the need to build a message snapshot while sill providing the necessary information for the UI.
Allow the agent path to be specified when using to_ag_ui.
Reduce the log level for the request done message in the AG-UI adapter to debug level.
Add missing `from __future__ import annotations` imports to ensure ensure that only relevant type annotations are processed at runtime. Fix incorrect import of `dataclass` in `args.py`.
Switch from additional tools to the new toolset system.
* Update examples to use `to_ag_ui` * Use relative imports where appropriate * Remove `path` and `logger` parameters from `to_ag_ui` and dependencies * Clean up import failure messages * Improve FastAGUI doc comment * Use `PrefixedToolset` eliminating manual tool prefixing * Use CallToolsNode to handle tool calls Also make StateDeps more strict, to avoid runtime failures.
Add some no cover pragmas in existing code to avoid coverage check failure. Correct raise to avoid resetting traceback in `AgentGraph`.
639d60b
to
d8c6cb5
Compare
AG-UI adapter enabling integration with the AG-UI protocol via the Agent.to_ag_ui() method.
This includes examples for all features in the AG-UI dojo.
Fixes: ag-ui-protocol/ag-ui#5